*----------------------------------------------------------------------------------------------------------	* 
* RESEARCHERS:		Emtiaz Hritan, Tim Bruckner									   							*
* PROGRAMMED BY:	Emtiaz Hritan																			*
* DESCRIPTION:      The Politics of Birth: How Local Representation Shapes Maternal-Infant Outcomes				 						 	*
* CREATED:			Nov. 19, 2025																		   	*
* LAST MODIFIED:	Jan. 27, 2026													       					*
*----------------------------------------------------------------------------------------------------------	*

clear all
set more off
* Set local paths
* Set this local datapath equal to the folder location for data
	local datapath "C:\Users\name\Replication Files Politics of Birth\Data"
* Set this local outputpath equal to the folder location for outcome like tables
	local outputpath "C:\Users\name\Replication Files Politics of Birth\Outcome"


* Install necessary packages
ssc install reghdfe
ssc install ftools
ssc install grstyle, replace
ssc install palettes, replace
ssc install colrspace, replace
ssc install ppmlhdfe, replace 
ssc install jwdid, replace 
ssc install csdid, replace 
ssc install drdid, replace 
ssc install did_imputation, replace
ssc install frause, replace
frause mpdta.dta, clear
ssc install hdfe, replace 
ssc install event_plot, replace
ssc install addplot, replace


**************************************************************************************************
** Table A6: Mechanism Results: Effect of First Black Candidate Win on Local Government Finance **
**************************************************************************************************

clear all
*Import covariates file
use "`datapath'\all_covariates", clear 
* Election data ranges from 1989 to 2021; limit the covariates to this ranges
keep if inrange(year, 1990, 2019)
tempfile covariates
    save `covariates' 
	
*Import county health covariates file
use "`datapath'\county_covariates_health.dta", clear 
tempfile health_covariates
    save `health_covariates' 	
	
	
	
* Keep the counties in our sample 
clear all
use "`datapath'\county_election.dta"
keep county_fips  year_female year_black year_hispanic year_asian
duplicates drop county_fips, force
* Null out first-year vars outside the window of 1990-2019. WE also want at least one pre-treatment year inside the analysis window.
drop if (!missing(year_female)   & !inrange(year_female,   1990, 2019)) ///
  |    (!missing(year_black)     & !inrange(year_black,    1990, 2019)) ///
  |    (!missing(year_hispanic)  & !inrange(year_hispanic, 1990, 2019)) ///
  |    (!missing(year_asian)     & !inrange(year_asian,    1990, 2019))
sort county_fips
tempfile sample_county
    save `sample_county' 

* import governement finance file
use "`datapath'\year_1990_2019_clean.dta"	
merge m:1 county_fips using `sample_county' 
keep if _merge==3
drop _merge


* Merge it with county covariates

merge 1:1 county_fips year using `covariates'
keep if _merge==3
drop _merge

* Merge it with county health covariates

merge 1:1 county_fips year using `health_covariates'
drop if _merge==2
drop _merge

xtset county_fips year
cd "`datapath'"
rename healthdirectexpend_19 hltdirexp
rename healthcapitaloutlay_19 hltcapout
rename healthtotalexpend_19 hlttotexp
rename totalhospitaldirexp_19 tothspdirexp
rename totalhospitalcapout_19 tothspcapout
rename totalhospitaltotalexp_19 tothsptotexp 
rename ownhospitaltotalexp_19 ownhsptotexp
rename publicwelftotalexp_19 pubwelftotexp
rename welfvendpmtsmedical_19 welfvendpmtsmed
save final_finance.dta, replace

* Impact of black candidate win on local government finance 

clear all 
use "`datapath'\final_finance.dta"
	
* 1-year induction
gen treat_black = year >= year_black + 1 if !missing(year_black)
replace treat_black = 0 if missing(treat_black)	



*-------------------------------------------*
* Define outcome lists
*-------------------------------------------*

* We cannot take logs directly (ln(0) missing). Many counties have no hospital, no welfare program, or report zero capital spending in many years. Let.s take Inverse Hyperbolic Sine (IHS)		  

foreach v in hlttotexp hltdirexp hltcapout ///
             pubwelftotexp welfvendpmtsmed tothsptotexp tothspdirexp ///
			 tothspcapout ownhsptotexp {
    gen ihs_`v' = asinh(`v')
}



local outcomes_all ihs_hlttotexp ihs_hltdirexp ihs_hltcapout ///
             ihs_pubwelftotexp ihs_welfvendpmtsmed ihs_tothsptotexp ihs_tothspdirexp ///
			 ihs_tothspcapout ihs_ownhsptotexp
					
*-------------------------------------------*
* Define covariates lists
*-------------------------------------------*
* County covariates					
*LaborForce Employed Unemployed UnemploymentRate pop_total pop_male pop_female pop_white pop_black pop_ai_an pop_asian pop_hispanic pop_nonhispanic pop_under5 pop_under25 pop_25_34 pop_35plus pop_65plus share_under5 share_under25 share_25_34 share_35plus share_65plus earnings transfers 

* Economic variables: earnings, transfers, pop_total, UnemploymentRate

* Per-capita and logs
gen earn_pc = earnings/pop_total if pop_total>0
gen trans_pc = transfers/pop_total if pop_total>0
gen l_earn_pc = ln(earn_pc) if earn_pc>0
gen l_trans_pc = ln(trans_pc) if trans_pc>0
gen black_share= pop_black/pop_total if pop_total>0
gen hispanic_share= pop_hispanic/pop_total if pop_total>0
gen female_share= pop_female/pop_total if pop_total>0
gen l_population = ln(pop_total)

* After xtset county_fips year, generate lags for the shares you built earlier
foreach v in female_share black_share hispanic_share l_population ///
          l_earn_pc l_trans_pc UnemploymentRate ///
    share_under25 share_25_34 share_65plus share_under5 {
    capture gen L1_`v' = L.`v'
}


local covariates_demography ///
    L1.UnemploymentRate L1.l_earn_pc L1.l_trans_pc ///
    L1_l_population L1_female_share L1_black_share L1_hispanic_share ///
    L1_share_under25 L1_share_25_34 L1_share_65plus L1_share_under5 
    
				

*-------------------------------------------*
* Loop: All finance outcomes 
*-------------------------------------------*

gen l_LaborForce = ln(LaborForce) if LaborForce>0				
local outcomes_labor UnemploymentRate l_earn_pc l_trans_pc l_LaborForce

eststo clear
foreach y of local outcomes_labor {
    eststo: reghdfe `y' treat_black , absorb(county_fips year) vce(cluster county_fips)
}
esttab using results_labor_black.csv, b(3) se(3) r2 replace
eststo clear



local outcomes_raw hlttotexp hltdirexp hltcapout ///
             pubwelftotexp welfvendpmtsmed tothsptotexp tothspdirexp ///
			 tothspcapout ownhsptotexp

eststo clear
foreach y of local outcomes_raw {
    eststo: ppmlhdfe `y' treat_black , absorb(county_fips year) vce(cluster county_fips)
}
esttab using results_poisson_black.csv, b(3) se(3) r2 replace
eststo clear

eststo clear
foreach y of local outcomes_all {
    eststo: reghdfe `y' treat_black `covariates_demography', absorb(county_fips year) vce(cluster county_fips)
}
esttab using results_all_black_covariates.csv, b(3) se(3) r2 replace
eststo clear

eststo clear
foreach y of local outcomes_all {
    eststo: reghdfe `y' treat_black , absorb(county_fips year) vce(cluster county_fips)
}
esttab using results_all_black.csv, b(3) se(3) r2 replace
eststo clear


*--------------------------------------------------------------------------
* END
*--------------------------------------------------------------------------


*---------------------------------------------------------------------------------
** Table A7: Mechanism Results: Effect of First Black Candidate Win on Arrests **
*---------------------------------------------------------------------------------

* Keep the counties in our sample 
clear all
use "`datapath'\county_election.dta"
keep county_fips  year_female year_black year_hispanic year_asian
duplicates drop county_fips, force
* Null out first-year vars outside the window of 1990-2019. WE also want at least one pre-treatment year inside the analysis window.
drop if (!missing(year_female)   & !inrange(year_female,   1990, 2019)) ///
  |    (!missing(year_black)     & !inrange(year_black,    1990, 2019)) ///
  |    (!missing(year_hispanic)  & !inrange(year_hispanic, 1990, 2019)) ///
  |    (!missing(year_asian)     & !inrange(year_asian,    1990, 2019))
sort county_fips
tempfile sample_county
    save `sample_county' 

* import governement finance file
use "`datapath'\arrests_1995_2019.dta"	
merge m:1 county_fips using `sample_county' 
keep if _merge==3
drop _merge

save "`datapath'\arrests_clean.dta", replace
clear all

* Impact of black candidate win on local government finance 
use "`datapath'\arrests_clean.dta" 

* Setting up a relative path to store the tables
cd "`outputpath'"

// Get all demographic variables from M0_9 to AN
ds M0_9-AN
local count_vars `r(varlist)'

// Drop observations with any negative value in demographic variables
foreach var of local count_vars {
    drop if `var' < 0 & !missing(`var')
}

* Traditional Two-way Fixed Effect model

xtset county_fips year
	
* 1-year induction
gen treat_black = year >= year_black + 1 if !missing(year_black)
replace treat_black = 0 if missing(treat_black)	

*-------------------------------------------*
* Define outcome lists
*-------------------------------------------*

gen arrests_female_15_44 = F15 + F16 + F17 + F18 + F19 + F20 + F21 + F22 + F23 + F24 + F25_29 + F30_34 + F35_39 + F40_44


local outcomes_all arrests_female_15_44 AB AA AH ///
             JB JA JH total_males total_females
			
				

*-------------------------------------------*
* Loop: All arrests outcomes 
*-------------------------------------------*


eststo clear
foreach y of local outcomes_all {
    eststo: ppmlhdfe `y' treat_black , absorb(county_fips year) vce(cluster county_fips)
}
esttab using results_poisson_black.csv, b(3) se(3) r2 replace
eststo clear

clear all 

*--------------------------------------------------------------------------
* END
*--------------------------------------------------------------------------


*---------------------------------------------------------------------------------
** Table A8: Mechanism Results: Effect of First Black Candidate Win on Evictions **
*---------------------------------------------------------------------------------
	
* Keep the counties in our sample 
clear all
use "`datapath'\county_election.dta"
keep county_fips  year_female year_black year_hispanic year_asian
duplicates drop county_fips, force
* Null out first-year vars outside the window of 1990-2019. WE also want at least one pre-treatment year inside the analysis window.
drop if (!missing(year_female)   & !inrange(year_female,   1990, 2019)) ///
  |    (!missing(year_black)     & !inrange(year_black,    1990, 2019)) ///
  |    (!missing(year_hispanic)  & !inrange(year_hispanic, 1990, 2019)) ///
  |    (!missing(year_asian)     & !inrange(year_asian,    1990, 2019))
sort county_fips
tempfile sample_county
    save `sample_county' 

clear 
* Import eviction data
import delimited "`datapath'\county_court-issued_2000_2018.csv"
rename fips_county county_fips 
merge m:1 county_fips using `sample_county' 
keep if _merge==3
drop _merge

save "`datapath'\eviction_clean.dta", replace
clear all

* Impact of black candidate win on local government finance 

use "`datapath'\eviction_clean.dta" 

* Setting up a relative path to store the tables
cd "`outputpath'"


* Traditional Two-way Fixed Effect model

xtset county_fips year
	
* 1-year induction
gen treat_black = year >= year_black + 1 if !missing(year_black)
replace treat_black = 0 if missing(treat_black)	

*-------------------------------------------*
* Define outcome lists
*-------------------------------------------*

gen filing_rate = 100* (filings_observed / renting_hh )
				

*-------------------------------------------*
* Loop: All arrests outcomes 
*-------------------------------------------*


eststo clear

eststo: ppmlhdfe filings_observed treat_black , absorb(county_fips year) vce(cluster county_fips)
esttab using results_poisson_black.csv, b(3) se(3) r2 replace
eststo clear


eststo clear

eststo: reghdfe filing_rate treat_black , absorb(county_fips year) vce(cluster county_fips)
esttab using results_black.csv, b(3) se(3) r2 replace
eststo clear

clear all 


*--------------------------------------------------------------------------
* END
*--------------------------------------------------------------------------
